package tech.bmatch.redpack.service.impl;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import tech.bmatch.redpack.model.RedPack;
import tech.bmatch.redpack.service.RedPackService;

import java.io.File;
import java.io.IOException;
import java.util.List;


/**
 * 将红包对象存储为json文件
 */
public abstract class RedPackServiceFileStoreImpl implements RedPackService {

    private static ObjectMapper objectMapper = new ObjectMapper();
    private static File file = new File("./data.json");


    public void store(List<RedPack> redPackList ){
        if(redPackList==null) return;
        try{
            objectMapper.writeValue(file,redPackList);
        }catch (IOException e){
            System.out.println("write redPack from file error");
        }
    }

}
